package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.SmsService;
import com.itheima.health.vo.SmsLoginParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
@RequestMapping("/mobile/login")
public class MobileLoginController {
    @Autowired
    private SmsService smsService;
    @PostMapping("/smsLogin")
    public Result login(@RequestBody SmsLoginParam param, HttpServletRequest request) {
    //验证码验证
        boolean success = smsService.checkValidateCode("MOBILE_SIGNIN", param.getTelephone(), param.getValidateCode());
        if (!success) {
            return new Result(false, MessageConst.VALIDATECODE_ERROR);
        }
        log.info("[登录成功>>>>>>>>>>>>>>>]");
        return new Result(true, MessageConst.LOGIN_SUCCESS);
    }
}
